//
//  AboutUsViewController.m
//  BusinessApp
//
//  Created by CccDaxIN on 2016/10/25.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "AboutUsViewController.h"
#import "WebViewJavascriptBridge.h"
#import "WKWebViewJavascriptBridge.h"

@interface AboutUsViewController ()<UIWebViewDelegate>
{
    UIWebView *webview;
}
@end

@implementation AboutUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"关于我们";
    
    [self aboutOurDataRequest];
    /*
     *返回
     */
    UIImage *aboutUsBackImage = [UIImage imageNamed:@"左箭头"];
    aboutUsBackImage = [aboutUsBackImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:aboutUsBackImage style:UIBarButtonItemStylePlain target:self action:@selector(aboutUsBackAction)];
    

    
    // Do any additional setup after loading the view.
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}
#pragma amrk -- 关于我们
- (void)aboutOurDataRequest{
    [GDJHttpTool get:AboutUs params:@{@"ShouJiHao":GETPHONE,@"Duuid":GETUUID,@"Token":GETTOKEN} success:^(id responseObj) {
        NSLog(@"从你的全世界路过 %@",responseObj);
        [SVProgressHUD showWithStatus:@"正在加载"];
        //查看错误码
        NSInteger err = [[responseObj valueForKey:@"Err"]integerValue];
        NSLog(@"争取吧%ld",(long) err);
        if (err == 0) {
            [SVProgressHUD dismiss];
            webview = [[UIWebView alloc]initWithFrame:CGRectMake(0,64,kScrernWidth, kScrernHeight-64)];
            webview.backgroundColor = [UIColor whiteColor];
            [webview setUserInteractionEnabled:YES];//是否支持交互
            webview.delegate=self;
//            [webview setOpaque:NO];//opaque是不透明的意思
//            [webview setScalesPageToFit:YES];//自动缩放以适应屏幕
            [self.view addSubview:webview];
            
            NSString *string_url = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,responseObj[@"Article"][@"Url"]];
            NSURL *url = [NSURL URLWithString:string_url];
            [webview loadRequest:[NSURLRequest requestWithURL:url]];
            
            
//            // 开启日志，方便调试
//            [WebViewJavascriptBridge enableLogging];
//            
//            //    第二步：给ObjC与JS建立桥梁
//            
//            // 给哪个webview建立JS与OjbC的沟通桥梁
//            WebViewJavascriptBridge *bridge = [[WebViewJavascriptBridge alloc]init];
//            bridge = [WebViewJavascriptBridge bridgeForWebView:webview];
//            
//            // 设置代理，如果不需要实现，可以不设置
//            //    [bridge WebViewDelegate:self];
//            
//            //    第三步：注册HandleName，用于给JS端调用iOS端
//            
//            // JS主动调用OjbC的方法
//            // 这是JS会调用getUserIdFromObjC方法，这是OC注册给JS调用的
//            // JS需要回调，当然JS也可以传参数过来。data就是JS所传的参数，不一定需要传
//            // OC端通过responseCallback回调JS端，JS就可以得到所需要的数据
//            [bridge registerHandler:@"getUserIdFromObjC"handler:^(id data, WVJBResponseCallback responseCallback) {
//                NSLog(@"js call getUserIdFromObjC, data from js is %@", data);
//                if (responseCallback) {
//                    // 反馈给JS
//                    responseCallback(@{@"userId": @"123456"});
//                }
//            }];
//            
//            [bridge registerHandler:@"getBlogNameFromObjC"handler:^(id data, WVJBResponseCallback responseCallback) {
//                NSLog(@"js call getBlogNameFromObjC, data from js is %@", data);
//                if (responseCallback) {
//                    // 反馈给JS
//                    responseCallback(@{@"blogName": @"星仔"});
//                }
//            }];
//            //    第四步：直接调用JS端注册的HandleName
//            [bridge callHandler:@"getUserInfos"data:@{@"name": @"ddsds"}responseCallback:^(id responseData) {
//                NSLog(@"from js: %@", responseData);
//            }];
        }else{
            NSLog(@"%@",responseObj[@"ErrMsg"]);
            [SVProgressHUD showErrorWithStatus:responseObj[@"ErrMsg"]];
            return;
        }
    }failure:^(NSError *error) {
        NSLog(@"error::%@",error);
    }];
}

//- (void)webViewDidFinishLoad:(UIWebView *)webView{
//    
//    NSLog(@"哈哈哈哈哈 我的天哪");
//    // 禁用 页面元素选择
//    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
//    
//    //     禁用 长按弹出ActionSheet
//    [webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
//}




- (void)aboutUsBackAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
